
package com.twu.biblioteca;

import java.util.Scanner;

public class UserInteraction implements UserInterface{

    public int getMenuOption() {
        Scanner scanner = new Scanner(System.in);
        int option;
        displayResultString("Enter the choice : ");
        option = scanner.nextInt();
        return option;
    }
    public String getBookTitle() {
        Scanner scanner = new Scanner(System.in);
        String title = new String();
        displayResultString("Enter the title of the book : ");
        title = scanner.nextLine();
        return title;
    }

    public String getMovieTitle() {
        Scanner scanner = new Scanner(System.in);
        String title = new String();
        displayResultString("Enter the title of the movie : ");
        title = scanner.nextLine();
        return title;
    }

    public String getBookAuthor() {
        Scanner scanner = new Scanner(System.in);
        String author = new String();
        displayResultString("Enter the author of the book : ");
        author = scanner.nextLine();
        return author;
    }
    public String getMovieDirector() {
        Scanner scanner = new Scanner(System.in);
        String director = new String();
        displayResultString("Enter the director of the movie : ");
        director = scanner.nextLine();
        return director;
    }
    public int getBookYearOfPublication() {
        Scanner scanner = new Scanner(System.in);
        int year;
        displayResultString("Enter the year of publication of book: ");
        year = scanner.nextInt();
        return year;
    }
    public int getMovieYearOfRelease() {
        Scanner scanner = new Scanner(System.in);
        int year;
        displayResultString("Enter the year of release of movie: ");
        year = scanner.nextInt();
        return year;
    }
    public int getMovieRating() {
        Scanner scanner = new Scanner(System.in);
        int rating;
        displayResultString("Enter the rating of the movie: ");
        rating = scanner.nextInt();
        return rating;
    }

    public void displayResultString(String result) {
        System.out.println(result);

    }

    public void displayMenuActionResult(MenuActionResult menuActionResult) {
        displayResultString("\n\t\t\t\tLog Message\n\t\t\t\t===========");
        if ( menuActionResult.getState() == true)
            displayResultString("Successful Operation!! "+menuActionResult.getResultString());
        else {
            displayResultString("Operation failed... "+menuActionResult.getResultString());
        }
    }

    private void displayBookDetails(Book book) {

        displayResultString(String.format("\n%-40s%-40s%-40s" ,book.getTitle(),book.getAuthor(),book.getYearOfPublication()));
    }
    private void displayMovieDetails(Movie movie) {

        displayResultString(String.format("\n%-40s%-40s%-40s%-40s" ,movie.getTitle(),movie.getDirector(),movie.getYearOfPublication(),movie.getRating()));
    }

    public void displayLibraryItemDetails(LibraryItem libraryItem) {
        if ( libraryItem instanceof Book)
            displayBookDetails((Book)libraryItem);
        else
            displayMovieDetails((Movie)libraryItem);
    }

    public void displayUserInformation (UserInformation userInformation) {
        displayResultString(String.format("\n%-40s%-40s%-40s" ,userInformation.getName(),userInformation.getEmail(),userInformation.getPhoneNumber()));
    }
    public String getUserName() {
        Scanner scanner = new Scanner(System.in);
        String userName;
        displayResultString("Enter the user name: ");
        userName = scanner.nextLine();
        return userName;
    }
    public String getPassword() {
        Scanner scanner = new Scanner(System.in);
        String password;
        displayResultString("Enter the password: ");
        password = scanner.nextLine();
        return password;
    }
}
